package com.ylbh.modules.accessory;

import com.ylbh.common.pojo.goods.dto.GoodsDTO;
import com.ylbh.common.utils.FastJsonUtil;
import com.ylbh.modules.goods.service.ShoppingGoodsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.math.BigDecimal;
import java.text.DecimalFormat;
import java.util.List;

/**
 * @author: czx
 * @date: 2019/11/28 11:20
 */
@RestController
@RequestMapping("costingPrice")
public class GoodsCostingPriceController {

    @Autowired
    private ShoppingGoodsService shoppingGoodsService;

    public void modifyAllGoodsCostingPrice() {

        List<GoodsDTO> list = shoppingGoodsService.getAllGoods();
        for (GoodsDTO dto:list) {
            List<GoodsInventoryDetails> gitd = FastJsonUtil.toList(dto.getGoodsInventoryDetail(), GoodsInventoryDetails.class);
            BigDecimal minCostingPrice = null;
            for (GoodsInventoryDetails vo:gitd) {
                if (null == minCostingPrice) {
                    minCostingPrice = new BigDecimal(vo.getGoodsCostingPrice());
                } else {
                    if (minCostingPrice.compareTo(new BigDecimal(vo.getGoodsCostingPrice())) == 1) {
                        minCostingPrice = new BigDecimal(vo.getGoodsCostingPrice());
                    }
                }
                vo.setShowCostingPrice(new DecimalFormat("#.00").format(new BigDecimal(vo.getGoodsCostingPrice()).multiply(new BigDecimal("0.7"))));
            }
            dto.setGoodsCostingPrice(minCostingPrice);
        }
    }
}
